package cn.jishiyu11.xeqb.base

import android.app.Application
import android.util.Log
import cn.jishiyu11.xeqb.utils.DensityHelper
import cn.jishiyu11.xeqb.utils.PhoneInfoDeviceAndVersion
import cn.jishiyu11.xeqb.utils.getAppPhoneDeviceIdAndVersion

import com.tencent.smtt.sdk.QbSdk
import com.umeng.analytics.MobclickAgent

import com.meiqia.core.callback.OnInitCallback
import com.meiqia.meiqiasdk.util.MQConfig
import com.mob.MobSDK

/**
 * Created by zsy_zj on 2017/6/23.
 * Application 开始打开启动页面
 */

class XEQBApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        DensityHelper(this,360F).activate()
        jsyapplication = this
        // 设置该CrashHandler为程序的默认处理器
        val catchExcep = cn.jishiyu11.xeqb.base.UnCeHandler(this)
        Thread.setDefaultUncaughtExceptionHandler(catchExcep)
        //使用集成测试服务
        MobclickAgent.setDebugMode(true)
        initTBS()
        MobSDK.init(this)//ShareSDk
        PhoneInfoDeviceAndVersion  = getAppPhoneDeviceIdAndVersion(this)
    }


    /**
     * 初始化TBS浏览服务X5内核
     */
    private fun initTBS() {
        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        QbSdk.setDownloadWithoutWifi(true)//非wifi条件下允许下载X5内核
        val cb = object : QbSdk.PreInitCallback {

            override fun onViewInitFinished(arg0: Boolean) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0)
            }

            override fun onCoreInitFinished() {}
        }
        //x5内核初始化接口
        QbSdk.initX5Environment(applicationContext, cb)
    //美洽客服
        initMQ("a129b8dd52feab662ab2072bdd0d80ac")
    }


//
//    // 替换成自己的key
    fun initMQ(key:String){
        MQConfig.init(this,key,object : OnInitCallback {
            override fun onSuccess(p0: String?) {

            }

            override fun onFailure(p0: Int, p1: String?) {

            }

        })

    }

    companion object {
        var jsyapplication: Application? = null
    }


}
